<?php

/**
 * doctor_review actions.
 *
 * @package    docplus.co.za
 * @subpackage doctor_review
 * @author     Fox Matuku
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class doctor_reviewActions extends sfActions
{
    /**
     * Executes reviews action
     *
     * @param sfRequest $request A request object
     */
    public function executeReviews(sfWebRequest $request)
    {
        $this->doctor = DoctorTable::getInstance()->findOneByUserId($request->getParameter("doctor_id"));
    }

    /**
     * Executes reviewDone action
     *
     * @param sfRequest $request A request object
     */
    public function executeReviewDone(sfWebRequest $request)
    {
        $this->doctorReview = DoctorReviewTable::getInstance()->findOneById($request->getParameter("doctor_review_id"));
    }

    /**
     * Executes review action
     *
     * @param sfRequest $request A request object
     */
    public function executeReview(sfWebRequest $request)
    {
        $this->doctorId = $request->getParameter('doctor_id', null);
        $this->forward404Unless($this->doctorId);

        $doctorReview = new DoctorReview();
        $doctorReview->setDoctorId($this->doctorId);
        $doctorReview->setMemberId($this->getUser()->getMember()->getId());

        //die("I'm here..");
        $this->form = new DoctorReviewForm($doctorReview);
        if ($request->isMethod('post'))
        {
            $this->form->bind($request->getParameter($this->form->getName()));
            if ($this->form->isValid())
            {
                try
                {
                    $doctorReviewId = $this->form->save()->getId();

                    $this->getUser()->setFlash('notice', 'Thanks for successfully submitting your review on our system.');

                    echo $doctorReviewId;
                    exit;
                }
                catch (Exception $e)
                {
                    
                }
            }
        }
    }
    
    /**
     * Executes rate action
     *
     * @param sfRequest $request A request object
     */
    public function executeRate(sfWebRequest $request)
    {
        if ($request->hasParameter("doctor_review_id") && $request->hasParameter("rating_value"))
        {
            DoctorReviewRatingTable::getInstance()->updateOrCreateByDoctorReviewIdAndRatingValue($request->getParameter("doctor_review_id"), $request->getParameter("rating_value"));
            $this->doctorReview = DoctorReviewTable::getInstance()->findOneById($request->getParameter("doctor_review_id"));
        }
    }
}
